package team.kirohuji.repository.jpa.tidings;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import team.kirohuji.domain.tidings.Notify;
import team.kirohuji.domain.tidings.UserNotify;

@Repository
public interface UserNotifyRepository extends JpaRepository<UserNotify,Integer>{
	@Query(value="SELECT * from user_notify where notify_id = ?1",nativeQuery=true)
	public List<UserNotify> findAllByNotifyId(Integer notifyId);
	
	@Query(value="SELECT * from user_notify where user_id = ?1",nativeQuery=true)
	public List<UserNotify> findAllByUserId(Integer userId);
	
	@Query(value="SELECT * from user_notify where notify_id = ?1 and user_id = ?2",nativeQuery=true)
	public UserNotify findAllByNotifyIdAndUserId(Integer notifyId, Integer userId);

	@Query(value="update user_notify set is_read =b'1' where notify_id = ?1 and user_id = ?2",nativeQuery=true)
	public UserNotify updateReadByNotifyIdAndUserId(Integer notifyId, Integer userId);
	
	@Query(value="SELECT count(*) from user_notify where user_id = ?1 and is_read = 0",nativeQuery=true)
	public Long countByUserId(Integer userId);
	
}
